#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
double a[1005], z, f[1005], ans;
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < m; i++)
	{
		cin >> x >> y >> z;
		if (a[x] < z)
			break;
		else
		{
			a[x] -= z;
			f[y] = f[y] + z - floor(z);
			ans = ans + z - floor(z);
			a[y] += floor(z);
			if (f[y] > 1)
				break;
		}
	}
	printf("%.2lf", ans);
	return 0;
}
